//
///////////////////////////////

#ifndef GETPHOTOBYWEB_H
#define GETPHOTOBYWEB_H

#include <afxinet.h>
#include <fstream>
#include <string>

#define BUFFER_SIZE 4095;

class CWebGrabSession : public CInternetSession
{
public:
	//CWebGrabSession();
	CWebGrabSession(LPCTSR szAgentName);
	virtual ~CWebGrabSession();
	void CommonConstruct();

public:
	void SetStatus(LPCTSR fmt, ...);

public:
	CString GetErrorMessage();
	virtual void OnStatusCallback(DWORD dwContext, DWORD dwInternetStatus,
								  LPVOID lpvStatusInformation, 
								  DWORD dwStatusInformationLength);


protected:
	CString errorMessage;
};

class CGetPhotoByWed : public CObject
{
public:
	CGetPhotoByWed();
	virtual ~GetPhotoByWed();

public:
	using namespace std;
	typedef string::size_type POSITION;
	BOOL initialise(LPCSTR szAgentName = NULL);
	BOOL getFile(LPCTSR szURL, CString& strBuffer,
				 LPCSTR szAgentName = NULL);
	void Close();
	void InitFile();
	void CloseFile();

public:
	CString getRawHeaders();
	CString getSocksHttp();
	CString getErrorMessage();

	DWORD getPageStatusCode();
	SHORT getErrorCode();
	double getRate();

	void setUseProxy(bool use);
	void setProxy(LPCSTR proxy, WORD prot, bool use = true);
	void setProxyPort(UINT port);
	void setProxyServer(LPCSTP server);
	void setTimeOut(DWORD timeout);

protected:
	CWebGrabSession* m_p_session;
	DWORD m_timeout;

private:
	double	m_transtfer_rate;
	bool	m_use_proxy_flage;
	UINT	m_prot_num;
	DWORD	m_info_status_code;
	CString m_error_message;
	CString m_proxy;
	CString m_raw_headers;

	ifstream *in_file;
	ofstream *out_file;
	POSITION pos;

};




#endif